package com.wwwc.admin.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;

import com.wwwc.admin.web.database.*;
import com.wwwc.util.web.*;

public class MainBarServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
	
	try {
	    response.setContentType("text/html");
	    String user_ip       = request.getRemoteAddr();
	    HttpSession session  = request.getSession(true);
	    PrintWriter out      = response.getWriter();

	    ResourceBundle config = (ResourceBundle)session.getAttribute("Configuration");
	
	    if (config == null) {
		return;
	    }
	    
	    String local_ips   = config.getString("3wcenter.local_ips");
	    if(!user_ip.startsWith(local_ips)) {
		return;
	    }

	    String call_path = request.getContextPath()+request.getServletPath();
	    String id = (String)session.getAttribute("id");

	    if(id != null && id.equals("1")) {
		try {
		    RequestDispatcher rd = request.getRequestDispatcher("adminDatabaseManager?who=m");
		    rd.include(request,response);
		}
		catch (Exception e) {
		}
	    }

	    if(id != null && id.equals("2")) {
		try {
		    RequestDispatcher rd = request.getRequestDispatcher("adminUserAccountManager?who=m");
		    rd.include(request,response);
		}
		catch (Exception e) {
		}
	    }
	    if(id != null && id.equals("3")) {
		try {
		    RequestDispatcher rd = request.getRequestDispatcher("adminProductManager?who=m");
		    rd.include(request,response);
		}
		catch (Exception e) {
		}
	    }
	    if(id != null && id.equals("4")) {
		try {
		    RequestDispatcher rd = request.getRequestDispatcher("adminAccessLogServlet?who=m");
		    rd.include(request,response);
		}
		catch (Exception e) {
		}
	    }
	    if(id != null && id.equals("5")) {
		try {
		    RequestDispatcher rd = request.getRequestDispatcher("adminGenerateImageList?who=m");
		    rd.include(request,response);
		}
		catch (Exception e) {
		}
	    }
	}
	catch (Exception e) {
	    System.out.println("TopBarServlet:Exception:"+e);
	}
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws IOException, ServletException 
    {
	doPost(request, response);
    }
}








